/*
 * micro_libxml.h
 *
 *  Created on: Feb 27, 2012
 *      Author: Administrator
 *      this is a very light and portable xml library.
 */

#ifndef MICRO_LIBXML_H_
#define MICRO_LIBXML_H_
#include <sys/types.h>

#define micro_libxml_attribute_t struct micro_libxml_xmpp_attribute
struct micro_libxml_xmpp_attribute
{
	char occupied;
	char *attribute_name;
	int attribute_name_len;
	char *attribute_value;
	int attribute_value_len;
	char *attribute_ns;
	int attribute_ns_len;
	micro_libxml_attribute_t *next;
	micro_libxml_attribute_t *next_in_memory;
};
#define micro_libxml_xmpp_element_t struct micro_libxml_xmpp_element
struct micro_libxml_xmpp_element
{
	char occupied;
	char *element_name;//name
	int element_name_len;
	char *element_ns;//namespace
	int element_ns_len;
	char *element_value;//value
	int element_value_len;
	char *element_start;
	char *element_end;
	micro_libxml_attribute_t *attributes;
	micro_libxml_xmpp_element_t *childs;
	micro_libxml_xmpp_element_t *parent;
	micro_libxml_xmpp_element_t *next;
	micro_libxml_xmpp_element_t *next_in_memory;
};
enum MICRO_LIBXML_FOUND_ELEMENT_RETURN
{
	MICRO_LIBXML_FOUND_ELEMENT_RETURN_ERROR = -1,
	MICRO_LIBXML_FOUND_ELEMENT_RETURN_FREE_NOTHING = 0,
	MICRO_LIBXML_FOUND_ELEMENT_RETURN_FREE_CURRENT_ELEMENT = 1,
	MICRO_LIBXML_FOUND_ELEMENT_RETURN_FREE_ROOT = 2
};

#define micro_libxml_parser_t struct micro_libxml_parser
struct micro_libxml_parser;
typedef int (micro_libxml_read)(micro_libxml_parser_t *parser,void *userdata);
typedef enum MICRO_LIBXML_FOUND_ELEMENT_RETURN (micro_libxml_found)(micro_libxml_parser_t *parser,void *userdata,micro_libxml_xmpp_element_t *element);

struct micro_libxml_parser
{
	char *stopping;
	char *readbuffer;
	char *readbuffer_current;
	size_t readbuffer_len;
	size_t readbuffer_available_len;
	micro_libxml_read *read;
	micro_libxml_found *found;
};
int micro_libxml_parse_stream(micro_libxml_parser_t *parser,void *userdata);

int micro_libxml_init();
int micro_libxml_destroy();
micro_libxml_attribute_t *micro_libxml_findattribute(micro_libxml_xmpp_element_t *element,char *attributename);
micro_libxml_xmpp_element_t *micro_libxml_findelement(micro_libxml_xmpp_element_t *element,char *xpath);
#endif /* MICRO_LIBXML_H_ */
